import com.atshiyou.bean.Student;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.Reader;
import java.util.List;

public class Test_Copy {
    public static void main(String[] args) throws Exception {
//        1、加载配置文件
        Reader reader = Resources.getResourceAsReader("mybatis.xml");
        //2、得到SqlSessionFactoryBuilder
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        SqlSessionFactory build = builder.build(reader,"development2");
        //3、得到session对象
        SqlSession session = build.openSession();
        // 4、操作SQL
        //4.1指定分页的参数
        PageHelper.startPage(2,3);//第一页，每页显示三条
        //4.2 调取dao层方法
        List<Student> lists = session.selectList
                ("com.atshiyou.dao.StudentDao.findAll");
        //4.3创建分页工具类对象
        PageInfo<Student> info = new PageInfo<>(lists);
        //5.从分页info中获取数据
        List<Student> list = info.getList();
        for (Student student : list) {
            System.out.println(student);
        }
        System.out.println("总条数:"+info.getTotal());
        System.out.println("当前页条数:"+info.getSize());
        System.out.println("总页数:"+info.getPages());
        System.out.println("上一页:"+info.getPrePage());
        System.out.println("下一页:"+info.getNextPage());
        System.out.println("当前页:"+info.getPageNum());
        System.out.println("显示条数:"+info.getPageSize());

        session.close();
        reader.close();

    }
}
